<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加bug</title>
    <script src="js/jquery.js"></script>
    <link rel="stylesheet" href="js/layui/css/layui.css">
</head>
<body style="padding: 20px">
<form class="layui-form" action="">

    <div class="layui-form-item">
        <label class="layui-form-label">BUG标题：</label>
        <div class="layui-input-block">
            <input type="text" name="bugName" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">项目名称：</label>
        <div class="layui-input-block">
            <input type="text" name="proName" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块ID：</label>
        <div class="layui-input-block">
            <input type="text" name="funcId" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">BUG等级：</label>
        <div class="layui-input-block">
            <input name="bugLevel" type="radio" value="1：轻微" checked="checked" class="layui-input" title="1：轻微"/>
            <input name="bugLevel" type="radio" value="2：次要" class="layui-input" title="2：次要"/>
            <input name="bugLevel" type="radio" value="3：一般" class="layui-input" title="3：一般"/>
            <input name="bugLevel" type="radio" value="4：紧急" class="layui-input" title="4：紧急"/>
            <input name="bugLevel" type="radio" value="5：严重" class="layui-input" title="5：严重"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">创建日期：</label>
        <div class="layui-input-block">
            <input type="text" name="bugDate" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">最后处理日期：</label>
        <div class="layui-input-block">
            <input type="text" name="editDate"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">提交人员：</label>
        <div class="layui-input-block">
            <input type="text" name="bugDev" lay-verify="required" class="layui-input" value="${loginUser.username}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">BUG状态：</label>
        <div class="layui-input-block">
            <input name="bugStatus" type="radio" value="已修复" class="layui-input" title="已修复"/>
            <input name="bugStatus" type="radio" value="待修复" checked="checked" class="layui-input" title="待修复"/>
            <input name="bugStatus" type="radio" value="已关闭" class="layui-input" title="已关闭"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">解决形式：</label>
        <div class="layui-input-block">
            <input name="fixWay" type="radio" value="1：解决" class="layui-input" title="1：解决"/>
            <input name="fixWay" type="radio" value="2：不是错误" class="layui-input" title="2：不是错误"/>
            <input name="fixWay" type="radio" value="3：错误重复" class="layui-input" title="3：错误重复"/>
            <input name="fixWay" type="radio" value="4：无法重现" class="layui-input" title="4：无法重现"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注：</label>
        <div class="layui-input-block">
            <textarea type="text" name="bugText" class="layui-input" style="height: 100px;padding-left: 10px;" placeholder="请输入内容......"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn layui-bg-blue" lay-submit="" lay-filter="submit-button">添加</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="js/layui/layui.js" charset="utf-8"></script>
<script>
    //根据管理员、提交人员、开发人员控制修改字段的权限
    if("${loginUser.userType}" == "管理员"){
        //什么也不做：所有权限

    }else {
        //是提交人员：不能编辑编辑BUG状态、处理日期、解决形式、提交人员
        $("input[name='bugStatus']").attr("disabled","disabled")
        $("input[name='fixWay']").attr("disabled","disabled")
        $("input[name='editDate']").attr("disabled","disabled")
        $("input[name='bugDev']").attr("disabled","disabled")
    }
    layui.use(['form', 'layedit', 'laydate'], function () {
        let form = layui.form, layer = layui.layer, layedit = layui.layedit;
        //创建一个编辑器
        let editIndex = layedit.build('LAY_demo_editor');
        //自定义验证规则
        form.verify({
            content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听提交
        form.on('submit(submit-button)', function (data) {
            $.post("bugAdd", data.field, function () {
                let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
                parent.location.reload();//刷新父级页面

            }, "text");//这里用的是post提交，如果不懂可以参考JQuery中ajax提交
            return false;
        });
    });
</script>
</body>
</html>
